package com.ruoyi.web.controller.order;

import java.util.List;

import com.ruoyi.common.annotation.PropertyInject;
import com.ruoyi.common.enums.InjectType;
import com.ruoyi.order.domain.OrderFulfillment;
import com.ruoyi.order.service.IOrderFulfillmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单任务执行Controller
 *
 * @author testlove
 * @date 2021-07-08
 */
@RestController
@RequestMapping("/system/fulfillment")
@Api("订单执行管理")
public class OrderFulfillmentController extends BaseController
{
    @Autowired
    private IOrderFulfillmentService orderFulfillmentService;

    /**
     * 查询订单任务执行列表
     */
    @PreAuthorize("@ss.hasPermi('system:fulfillment:list')")
    @GetMapping("/list")
    @ApiOperation("查询所有订单任务执行")
    public TableDataInfo list(OrderFulfillment orderFulfillment)
    {
        startPage();
        List<OrderFulfillment> list = orderFulfillmentService.selectOrderFulfillmentList(orderFulfillment);
        return getDataTable(list);
    }

    /**
     * 导出订单任务执行列表
     */
    @PreAuthorize("@ss.hasPermi('system:fulfillment:export')")
    @Log(title = "订单任务执行", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出所有订单任务执行")
    public AjaxResult export(OrderFulfillment orderFulfillment)
    {
        List<OrderFulfillment> list = orderFulfillmentService.selectOrderFulfillmentList(orderFulfillment);
        ExcelUtil<OrderFulfillment> util = new ExcelUtil<OrderFulfillment>(OrderFulfillment.class);
        return util.exportExcel(list, "订单任务执行数据");
    }

    /**
     * 获取订单任务执行详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:fulfillment:query')")
    @GetMapping(value = "/{orderFulfillmentId}")
    public AjaxResult getInfo(@PathVariable("orderFulfillmentId") Long orderFulfillmentId)
    {
        return AjaxResult.success(orderFulfillmentService.selectOrderFulfillmentById(orderFulfillmentId));
    }

    /**
     * 新增订单任务执行
     */
    @PreAuthorize("@ss.hasPermi('system:fulfillment:add')")
    @Log(title = "订单任务执行", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增订单任务执行")
    @PropertyInject(type = InjectType.Insert)
    public AjaxResult add(@RequestBody OrderFulfillment orderFulfillment)
    {
        return toAjax(orderFulfillmentService.insertOrderFulfillment(orderFulfillment));
    }

    /**
     * 修改订单任务执行
     */
    @PreAuthorize("@ss.hasPermi('system:fulfillment:edit')")
    @Log(title = "订单任务执行", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改订单任务执行")
    @PropertyInject(type = InjectType.Update)
    public AjaxResult edit(@RequestBody OrderFulfillment orderFulfillment)
    {
        return toAjax(orderFulfillmentService.updateOrderFulfillment(orderFulfillment));
    }

    /**
     * 删除订单任务执行
     */
    @PreAuthorize("@ss.hasPermi('system:fulfillment:remove')")
    @Log(title = "订单任务执行", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderFulfillmentIds}")
    @ApiOperation("删除订单任务执行")
    public AjaxResult remove(@PathVariable Long[] orderFulfillmentIds)
    {
        return toAjax(orderFulfillmentService.deleteOrderFulfillmentByIds(orderFulfillmentIds));
    }
}
